/* GUI CONVERTED from bmasmt.p (converter v1.75) Sun Aug 13 21:21:46 2000 */
/* bmasmt.p - ADD / MODIFY ALTERNATE PRODUCT STRUCTURES                       */
/* Copyright 1986-2000 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                         */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                       */
/* REVISION: 6.0       LAST EDIT: 04/15/91      MODIFIED BY: emb *D342*/
/* REVISION: 7.0       LAST EDIT: 11/16/91               BY: pml *F048*       */
/* REVISION: 7.0       LAST EDIT: 03/24/92               BY: pma *F089*       */
/* REVISION: 7.0       LAST EDIT: 06/18/92      MODIFIED BY: emb *F671*/
/* REVISION: 7.3       LAST EDIT: 02/24/93      MODIFIED BY: sas *G729*/
/* REVISION: 7.3       LAST EDIT: 04/15/93      MODIFIED BY: pma *G956*/
/* REVISION: 7.3       LAST EDIT: 07/29/93      MODIFIED BY: emb *GD82*/
/* REVISION: 8.5       LAST EDIT: 10/19/94      MODIFIED BY: dzs *J020*/
/* REVISION: 8.5       LAST EDIT: 02/15/95      MODIFIED BY: tjs *J020*/
/* REVISION: 8.5       LAST MODIFIED: 07/31/96  BY: *J12T* Sue Poland */
/* REVISION: 8.5       LAST MODIFIED: 05/27/97  BY: *J1S6* Felcy D'Souza*/
/* REVISION: 8.5       LAST MODIFIED: 12/23/97  BY: *H1HP* Jean Miller */
/* REVISION: 8.6       LAST MODIFIED: 05/20/98  BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6       LAST MODIFIED: 08/20/98  BY: *J2WW* Sandesh Mahagaokar */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00 BY: *N0KK* jyn                  */

         /* DISPLAY TITLE */
         {mfdtitle.i "b+ "}/*GD82*/

         define new shared variable comp like ps_comp.
         define new shared variable par like ps_par.
         define new shared variable level as integer.
         define new shared variable qty as decimal.
         define new shared variable parent like ps_par.
         define new shared variable ps_recno as recid.
         define variable del-yn like mfc_logical initial no.
         define variable unknown_char as character initial ?.
/*F089*/ define variable ptstatus1 like pt_status.
/*F089*/ define variable ptstatus2 like pt_status.
/*G956*/ define buffer ptmstr for pt_mstr.

         /* DISPLAY SELECTION FORM */
         
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
            
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
pt_part        colon 27
            pt_desc1       no-label at 50
            pt_um          colon 27
            pt_desc2       no-label at 50
          SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



         /* SET EXTERNAL LABELS */
         setFrameLabels(frame a:handle).

         FORM /*GUI*/ 
            
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
pt_bom_code    colon 27
            pt_desc1       no-label at 50
            pt_desc2       no-label at 50
            ps_ref         colon 27
            skip(1)
            ps_rmks        colon 27
          SKIP(.4)  /*GUI*/
with frame b side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


         /* SET EXTERNAL LABELS */
         setFrameLabels(frame b:handle).

         /* DISPLAY */
         view frame a.
         view frame b.

/*F089*/ mainloop:
         repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


/*F089*/    ptstatus1 = "".
/*F089*/    ptstatus2 = "".
            clear frame b no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.

/*H1HP*     prompt-for pt_part editing: */
/*H1HP*/    prompt-for pt_part with no-validate editing:

               /* FIND NEXT/PREVIOUS  RECORD */
/*G956         {mfnp.i pt_mstr pt_part pt_part pt_part pt_part pt_part}  */
/*G956*/       {mfnp01a.i pt_mstr pt_part pt_part ""C"" pt_pm_code pt_part}

               if recno <> ? then do:
                 display pt_part pt_um pt_desc1 pt_desc2.
               end.
               recno = ?.
            end.    /* prompt-for pt_part */

            find pt_mstr no-lock using pt_part no-error.
            if not available pt_mstr then do:
                {mfmsg.i 16 3} /* ITEM NUMBER DOES NOT EXIST */
                next.
            end.

/*G956*/    if pt_pm_code = "C" then do:
/*G956*/        {mfmsg.i 225 3} /* CONFIGURED ITEM NOT ALLOWED */
/*G956*/        undo, retry.
/*G956*/    end.

/*J020*/    if pt_joint_type = "5" then do:
/*J020*/        /* BASE PROCESS MAY NOT HAVE AN ALTERNATE STRUCTURE */
/*J020*/        {mfmsg.i 6532 4}
/*J020*/        undo, retry.
/*J020*/    end.

/*F089*/    ptstatus1 = pt_status.

            display pt_part pt_um pt_desc1 pt_desc2.
            parent = pt_part.

            /* SET GLOBAL PART VARIABLE */
            global_part = parent.

/*F089*/    b-loop:
            repeat with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

               prompt-for pt_bom_code ps_ref editing:

                 /* FIND NEXT/PREVIOUS  RECORD */
                 {mfnp05.i ps_mstr ps_parcomp
                   "ps_par = parent and ps_ps_code = ""A"""
                   ps_comp "input pt_bom_code"}

                 if recno <> ? then do:
                   find pt_mstr where pt_part = ps_comp no-lock no-error.
/*F671*/               find bom_mstr no-lock where bom_parent = ps_comp no-error.
                   if available pt_mstr then
                       display pt_part @ pt_bom_code pt_desc1 pt_desc2.
/*F671*/           else if available bom_mstr then
/*F671*/               display bom_parent @ pt_bom_code
/*F671*/                        bom_desc @ pt_desc1 "" @ pt_desc2.
                   else
                       display ps_par @ pt_bom_code "" @ pt_desc1 "" @ pt_desc2.

                   display ps_ref ps_rmks.
                 end. /* if recno <> ? */

               end. /* prompt-for pt_bom_code */

/*J020*/       find first ps_mstr where ps_comp = input pt_bom_code
/*J020*/                            and ps_ps_code = "J"
/*J020*/       no-lock no-error.
/*J020*/       if available ps_mstr and ps_ref = input ps_ref then do:
/*J020*/          {mfmsg.i 6523 4} /* UNIQUE REFERENCE NUMBER REQUIRED */
/*J020*/          undo, retry.
/*J020*/       end.

               if input pt_bom_code = "" then undo, retry.
               if input pt_bom_code = input pt_part then do:
                  {mfmsg.i 206 3} /* CYCLIC STRUCTURE NOT ALLOWED. */
                  undo, retry.
               end.

/*G956*/       comp = input pt_bom_code.
/*G956*/       if not can-find(ptmstr where ptmstr.pt_part = comp)
/*G956*/       and not can-find(bom_mstr where bom_parent = comp) then do:
/*G956*/          {mfmsg.i 231 3} /*ITEM NUMBER OR BOM CODE MUST EXIST */
/*G956*/          undo, retry.
/*G956*/       end.

/*F671*        find pt_mstr where pt_part = input pt_bom_code no-lock no-error. */
/*G729*/       find bom_mstr where
/*G729*/            bom_parent = input pt_bom_code
/*G729*/       no-lock no-error.
               if available bom_mstr then do:
/*J12T*           {fsbomv.i "input pt_bom_code" 2}   */
/*J12T*/          /* PREVENT USER FROM SPECIFYING A SERVICE BOM */
/*J12T*/          if bom_fsm_type = "FSM" then do:
/*J12T*/             {mfmsg.i 7487 3} /* THIS IS AN SSM BILL OF MATERIAL */
/*J12T*/             undo, retry.
/*J12T*/          end.
               end.   /* if available bom_mstr */

               find ps_mstr where ps_par = input pt_part
                              and ps_comp = input pt_bom_code
                              and ps_ref = input ps_ref
               exclusive-lock no-error.

               if not available ps_mstr then do:

/*F671*           if not available pt_mstr then do:
 *                   {mfmsg.i 100 3}
 *                   undo, retry.
 ************     end. */

/*F089*/          substring(ptstatus1,9,1) = "#".
/*F089*/          if can-find(isd_det where isd_status = ptstatus1
/*F089*/                                and isd_tr_type = "ADD-PS") then do:
/*F089*/             {mfmsg02.i 358 3 substring(ptstatus1,1,2)}
                     /* RESTRICTED PROCEDURE FOR ITEM STATUS CODE */
/*F089*/             undo mainloop, retry.
/*F089*/          end.

/*F671*/          find pt_mstr where pt_part = input pt_bom_code no-lock no-error.
/*F671*/          if available pt_mstr then do:
/*F089*/             ptstatus2 = pt_status.
/*F089*/             substring(ptstatus2,9,1) = "#".
/*F089*/             if can-find(isd_det where isd_status = ptstatus2
/*F089*/                      and isd_tr_type = "ADD-PS") then do:
/*F089*/                {mfmsg02.i 358 3 substring(ptstatus2,1,2)}
/*F089*/                undo b-loop, retry.
/*F089*/             end.
/*F671*/          end.    /* if available pt_mstr */

                  create ps_mstr.
                  assign
                    ps_par = caps(input pt_part)
                    ps_comp = caps(input pt_bom_code)
                    ps_ref
                    ps_ps_code = "A"
                    ps_qty_per = 1.

                  ps_recno = recid(ps_mstr).

                  {gprun.i ""bmpsmta.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if ps_recno = 0 then do:
                     hide message no-pause.
                     {mfmsg.i 206 3} /* CYCLIC PRODUCT STRUCTURE NOT ALLOWED */
                     undo, retry.
                  end.

                  {mfmsg.i 1 1} /* CREATING NEW RECORD */

/*F671*/           if not can-find (first ps_mstr where ps_par =
/*F671*/                              input pt_bom_code)
/*F671*/           then do:
/*F671*/              {mfmsg.i 100 2 } /* NO BILL OF MATERIAL EXISTS */
/*F671*/           end.

/*J2WW*  BEGIN ADD SECTION */

                   /* bom_mstr RECORD SHOULD BE CREATED FOR AN ITEM IF IT   */
                   /* DOES NOT EXIST                                        */

                   if not can-find (bom_mstr where bom_parent = input pt_part)
                   then do:

                       for first pt_mstr
                           fields (pt_bom_code pt_desc1 pt_desc2 pt_formula
                                   pt_joint_type pt_part pt_pm_code
                                   pt_status pt_um)
                           where pt_part = (input pt_part) no-lock:
                       end. /* FOR FIRST pt_mstr */

                       create bom_mstr.
                       assign bom_parent   = input pt_part
                              bom_userid   = global_userid
                              bom_mod_date = today
                              bom_batch_um = pt_um
                              bom_formula  = pt_formula.

                   end. /* IF NOT CAN-FIND */

/*J2WW*  END ADD SECTION */

               end.
/*GUI*/ if global-beam-me-up then undo, leave.
    /* if not available ps_mstr */

               /* STORE MODIFY DATE AND USERID */
               ps_mod_date = today.
               ps_userid = global_userid.

               recno = recid(ps_mstr).
               ps_recno = recno.

               /* SET GLOBAL PART VARIABLE */
               global_part = ps_comp.

               display ps_comp @ pt_bom_code ps_ref ps_rmks.

               ststatus = stline[2].
               status input ststatus.
               del-yn = no.

               do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


                  set ps_rmks go-on ("F5" "CTRL-D").

                  comp = ps_comp.
                  parent = ps_par.

                  /* DELETE */
                  if lastkey = keycode("F5")
                  or lastkey = keycode("CTRL-D")
                  then do:
                     del-yn = yes.
                     {mfmsg01.i 11 1 del-yn} /* PLEASE CONFIRM DELETE */
                     if del-yn = no then undo, retry.
                     delete ps_mstr.
                     del-yn = no.
                     {mfmsg.i 22 1} /* RECORD DELETED */
                  end.
                  else do:

/*F671*              if not available pt_mstr then do:
 *                     {mfmsg.i 100 3}
 *                     undo, retry.
 *********           end. */

                     if (ps_start <> ? and ps_end <> ?) then
                     if ps_start > ps_end then do:
                        {mfmsg.i 4 3} /* START DATE MUST BE PRIOR TO END */
                        undo, retry.
                     end.

/*J1S6**  BEGIN OF DELETED SECTION
 *                   if new(ps_mstr) then do:
 *                      {gprun.i ""bmpsmtb.p""}
 *                   end.
 *J1S6**  END OF DELETED SECTION*/

                  end.    /* else, lastkey <> F5, do */

/*J1S6**  BEGIN OF DELETED SECTION
 *                {inmrp.i &part=parent &site=unknown_char}
 *                {inmrp.i &part=comp   &site=unknown_char}
 *                release pt_mstr.
 *J1S6**  END OF DELETED SECTION*/

               end.
/*GUI*/ if global-beam-me-up then undo, leave.
    /* do on error undo retry */

            end.
/*GUI*/ if global-beam-me-up then undo, leave.
    /* b-loop repeat */

         end.   /* mainloop repeat */
         status input.
